<?php
/**
 * Created by PhpStorm.
 * User: lscm
 * Date: 14-8-6
 * Time: 下午4:38
 */
require("common/dbutil.php");
//$dbServer = "localhost";
//$dbUser = "adsAdmin";
//$dbPassword = "";
//$dbName = "surfingHelper";
$con=\common\dbutil::getConnect();
mysqli_set_charset($con,"utf8");
$result = mysqli_query($con,"SELECT * FROM ads WHERE AD_CATEGORY='3c' ORDER BY AD_CATEGORY");
$floors = array('sj'=>'手机', 'bjb'=>'笔记本');
$source_icons = array('jd.com'=>array('pic/img/jd.com.png','京东'),
                    'taobao.com'=>array('pic/img/taobao.com.png','淘宝'),
                    'tmall.com'=>array('pic/img/tmall.com.png','天猫'));
$ad_category = "3c";
require("head.php");
function buildItem($data){
    global $source_icons;
    $html = '<li class="good-item">'.
                '<a href="'.$data[ad_target_url].'" target="_blank"><img src="'.$data[ad_material_urls].'"></a>'.
            '<br>'.
            '<a href="'.$data[ad_target_url].'" class="good-title" target="_blank">'.$data[ad_title].'</a>'.
            '<div class="info-wrapper">'.
                '<span class="price">￥'.$data[ad_price].'</span>'.
                '<span class="source">'.
                    '<img src="'.$source_icons[$data[ad_from]][0].'">'.
                    '<span>'.$source_icons[$data[ad_from]][1].'</span>'.
                '</span>'.
            '</div>'.
            '</li>';
    return $html;
}
echo("<body>");
require("header.php");
?>
    <div id="channelShow" class="container">
        <div class="zhainan"></div>
        <div class="channel"></div>
    </div>
    <div class="container">
        <div class="main-content">
            <?php
            $cat_2="";
            $floorNum = 0;
            for ($i=0; $data = $result->fetch_array(MYSQLI_ASSOC);$i++){
                if($data[ad_category_2] != $cat_2){
                    if($cat_2 != ""){
                        echo('</ul>');
                    }
                    $cat_2 = $data[ad_category_2];
                    $floorNum+=1;
                    echo('<ul class="floor clearfix">');
                    $floorHtml= '<div class="floor-wrapper">'.
                                    '<span class="floor-icon">'.$floorNum.'F</span>'.
                                    '<span class="floor-title">'.$floors[$cat_2].'</span>'.
                                '</div>';
                    echo($floorHtml);
                }
                echo buildItem($data);
            }
            echo('</ul>');
            ?>
            </ul>

        </div>
    </div>
</body>
</html>